﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TTGameEngine;

namespace AliveCard
{
    public class ACPuppet : MonoBehaviour
    {
        [HideInInspector]
        public Transform objTF;
        //----------人物属性相关----------
        public string m_name;
        public ObjType m_objType;
        //----------移动相关----------
        [SerializeField]
        MoveInfo m_moveInfo = new MoveInfo(); //人物常规移动的信息。
        public float MoveSpeed = 6f;

        private void Awake()
        {
            initObj();
        }

        // Use this for initialization
        void Start()
        {

        }

        void initObj() {
            objTF = this.transform;
        }

        // Update is called once per frame
        void Update()
        {
            updateMove();
        }

        void updateMove()
        {
            if (m_moveInfo.IsMoving() == false) {
                return;
            }
            float dt = Time.deltaTime;
            m_moveInfo.moveSpeed = MoveSpeed;
            Vector3 nextPos = objTF.position;
            //强制位移
            //Tools.ObjForceStep(dt, m_puppet.objTF.position, m_puppet.PuppetForceMoveInfos.Values, out nextPos);
            //正常位移
            bool isMoveEnd = m_moveInfo.ObjMoveStep(dt, nextPos, out nextPos);
            //m_puppet.CurMoveDir = nextPos - m_puppet.transform.position;
            SimpleMove(nextPos);
            if (isMoveEnd)
            {
                //移动结束
                StopMove();
            }
        }

        void SimpleMove(Vector3 nextPos) {
//             if (DebugSetting.Self.moveUsingCharacterController)
//             {
//                 controller.Move(nextPos - objTF.position);
//             }
//             else
            {
                objTF.position = nextPos;
            }
        }

        public void StopMove()
        {
            m_moveInfo.StopMove();
//             if (StateID == PuppetStateID.Run)
//             {
//                 SetState(PuppetStateID.Stand);
//             }
        }

        public void MoveToPositionImm(Vector3 pos)
        {
            m_moveInfo.Reset();
            SimpleMove(pos);
        }

        Vector3 t_tagetMovePos;
        bool t_moveing = false;
        public void MoveToPosition(Vector3 pos) {
            m_moveInfo.Reset();
            m_moveInfo.moveID = MoveID.WalkOrRun;
            m_moveInfo.moveType = MoveType.MoveTargetPos;
            m_moveInfo.moveTargetPos = pos;
        }

        public void OnTouched() {
            string msg = string.Format("点击了 {0}:{1}", m_objType.ToString(), m_name);
            UIManager.Ins.ShowUI(UIFormID.UI_FloatMsg, new UIFloatMsgData(msg));
        }


    }
}
